package com.wwdx.service.impl;

import com.google.common.collect.Maps;
import com.wwdx.model.WwdxBookModel;
import com.wwdx.model.WwdxCopywriterModel;
import com.wwdx.service.WwdxCopywriterServiceI;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author liguoliang
 * @date 2018/3/30 11:38
 */
@Service
public class WwdxCopywriterServiceImpl extends BaseServiceImpl<WwdxCopywriterModel> implements WwdxCopywriterServiceI{

    @Override
    public Long selectModelCount(WwdxCopywriterModel model) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(4);
        String hql = "select count(1) from WwdxCopywriterModel\t"+getParams(model,params);
        return count(hql,params);
    }

    private String getParams(WwdxCopywriterModel model, Map<String, Object> params){
        StringBuilder sb = new StringBuilder("where 1=1\n");
        return sb.toString();
    }

    @Override
    public List<WwdxCopywriterModel> selectModelList(WwdxCopywriterModel model, Integer page, Integer rows) {
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(4);
        String hql = "from WwdxCopywriterModel\t"+getParams(model,params)+"\torder by userid";
        return find(hql, params, page, rows);
    }

    @Override
    public WwdxCopywriterModel getUserInfo(Long userid, String unionid, Integer page, Integer rows){
        WwdxCopywriterModel userInfo = this.getById(userid);
        WwdxBookModel model = WwdxBookModel.builder().status(0).type(0).userid(userid).build();
        userInfo.setBook_list(productService.bookList(wwdxBookService.selectModelList(model,page,rows),unionid));
        userInfo.setBook_count(wwdxBookService.selectModelCount(model));
        return userInfo;
    }
}